﻿using PropertyChanged;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using WPFTemplateLib.WpfHelpers;

namespace WPFPractice.Windows
{
    public partial class WinScrollTester : Window
    {
        public WinScrollTester()
        {
            InitializeComponent();
            DataContext = new ScrollTesterViewModel();
        }

        private void LeftScrollViewer_OnScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (sender is ScrollViewer scrollViewer)
            {
                centerScrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset);
            }
        }

        private void TopScrollViewer_OnScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (sender is ScrollViewer scrollViewer)
            {
                centerScrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset);
            }
        }

        private void CenterScrollViewer_OnScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (sender is ScrollViewer scrollViewer)
            {
                topScrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset);
                leftScrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset);
            }
        }
    }

    [AddINotifyPropertyChangedInterface]
    public class ScrollTesterViewModel : BindableBase
    {
        #region 绑定

        public List<string> LeftList { get; set; }
        public List<string> TopList { get; set; }
        public List<string> CenterList { get; set; }

        #endregion

        #region 方法

        public ScrollTesterViewModel()
        {
            Init();
        }

        private void Init()
        {
            LeftList = Enumerable.Range(1, 10).Select(x => x.ToString()).ToList();
            TopList = Enumerable.Range(1, 10).Select(x => x.ToString()).ToList();
            CenterList = Enumerable.Range(1, 100).Select(x => x.ToString()).ToList();
        }

        #endregion
    }
}
